
********************************************************************************
$ontext
This is the numerical bottom-up optimization model used in
St�ckl, F. and A. Zerrahn (2020): Substituting Clean for Dirty Energy: A Bottom-Up Analysis

This model is derived from
The Dispatch and Investment Evaluation Tool with Endogenous Renewables (DIETER).
Version 1.3.0, November 2018.
Written by Alexander Zerrahn and Wolf-Peter Schill.

This work is licensed under the MIT License (MIT).
For more information on this license, visit http://opensource.org/licenses/mit-license.php.
Whenever you use this code, please refer to http://www.diw.de/dieter.
We are happy to receive feedback under azerrahn@diw.de and wschill@diw.de.
$offtext
********************************************************************************


Variables
Z                Value objective function [Euro]
;

Positive Variables
G(n,tech,h)            Generation level in hour h [MWh]
G_RES(n,tech,h)          Generation renewables type res in hour h [MWh]

STO_IN(n,sto,h)          Storage inflow technology sto hour h [MWh]
STO_OUT(n,sto,h)         Storage outflow technology sto hour h [MWh]
STO_L(n,sto,h)           Storage level technology sto hour h [MWh]

N_TECH(n,tech)           Technology tech built [MW]
N_STO_E(n,sto)           Storage technology built - Energy [MWh]
N_STO_P_IN(n,sto)        Storage loading and discharging capacity built - Capacity [MW]
N_STO_P_OUT(n,sto)       Storage loading and discharging capacity built - Capacity [MW]
;




********************************************************************************

Equations
* Objective
obj                      Objective cost minimization

* Energy balance
con1b_bal                Energy Balance

* Maximum installation conditions
con1c_1_max_I_power      Maximum investment generation
con1c_2_max_I_sto_e      Maximum investment storage energy
con1c_3_max_I_sto_p_in   Maximum investment storage power in
con1c_4_max_I_sto_p_out  Maximum investment storage power out
con1c_5_max_biomass       Maximum biomass energy

* Capacity contraints and flexibility constraints
con1d_maxprod_dispatchable       Maximum generation dirty
con1e_maxprod_res                Maximum generation clean

* Storage constraints
con1f_1_stolev_start     Storage level: starting condition
con1f_2_stolev           Storage level
con1f_3_ending           Storage level: ending condition
con1g_1_stolev_max       Storage level: maximum
con1g_2_maxin_sto        Storage inout: maximum
con1g_3_maxout_sto       Storage output: maximum
con1h_1_maxout_lev       Storage: maximum output related to filling level
con1h_2_maxin_lev        Storage: maximum inout related to filling level
con1i_1_EtoP             Storage: maximum E to P ratio
con1i_2_inout            Storage: identity for power in and out capacities for batteries and pumped hydro

* Minimum restrictions for renewables and biomass
con1j_minRES             Clean energy share

* Sensitivity with electrification
conXa_total_demand       Total annual demand for electrification
conXb_max                Maximum hourly demand for electrification
;


********************************************************************************

* ---------------------------------------------------------------------------- *
***** Objective function *****
* ---------------------------------------------------------------------------- *

obj..
         Z =E=
                   sum( (h,map_n_tech(n,dis)) , kappa_v(n,dis)*G(n,dis,h) )
                 + sum( (h,map_n_sto(n,sto)) , kappa_v_sto_in(n,sto) * STO_IN(n,sto,h) + kappa_v_sto_out(n,sto) * STO_OUT(n,sto,h) )
                 + sum( map_n_tech(n,tech) , kappa_i(n,tech)*N_TECH(n,tech) )
                 + sum( map_n_tech(n,tech) , kappa_fix(n,tech)*N_TECH(n,tech) )
                 + sum( map_n_sto(n,sto) , kappa_i_sto_e(n,sto)*N_STO_E(n,sto) )
                 + sum( map_n_sto(n,sto) , kappa_fix_sto_e(n,sto)*N_STO_E(n,sto) )
                 + sum( map_n_sto(n,sto) , kappa_i_sto_p_in(n,sto)*N_STO_P_IN(n,sto) )
                 + sum( map_n_sto(n,sto) , kappa_fix_sto_p_in(n,sto)*N_STO_P_IN(n,sto) )
                 + sum( map_n_sto(n,sto) , kappa_i_sto_p_out(n,sto)*N_STO_P_OUT(n,sto) )
                 + sum( map_n_sto(n,sto) , kappa_fix_sto_p_out(n,sto)*N_STO_P_OUT(n,sto) )
;

* ---------------------------------------------------------------------------- *
***** Energy balance and load levels *****
* ---------------------------------------------------------------------------- *

* Energy balance
con1b_bal(n,hh)..
         delta(n,hh) + sum( map_n_sto(n,sto) , STO_IN(n,sto,hh) )
%power_to_x%$ontext
         + D_X(n,hh)
$ontext
$offtext
         =E=
         sum( map_n_tech(n,dis) , G(n,dis,hh)) + sum( map_n_tech(n,nondis) , G_RES(n,nondis,hh)) + sum( sto , STO_OUT(n,sto,hh) )
;


* ---------------------------------------------------------------------------- *
***** Maximum installation constraints *****
* ---------------------------------------------------------------------------- *


con1c_1_max_I_power(n,tech)$(map_n_tech(n,tech))..
         N_TECH(n,tech) =L= nu_p(n,tech)
;

con1c_2_max_I_sto_e(n,sto)$(map_n_sto(n,sto))..
         N_STO_E(n,sto) =L= nu_sto_e(n,sto)
;

con1c_3_max_I_sto_p_in(n,sto)$(map_n_sto(n,sto))..
         N_STO_P_IN(n,sto) =L= nu_sto_p(n,sto)
;

con1c_4_max_I_sto_p_out(n,sto)$(map_n_sto(n,sto))..
         N_STO_P_OUT(n,sto) =L= nu_sto_p(n,sto)
;

con1c_5_max_biomass(n,dis)$(map_n_tech(n,dis) AND nu_e(n,dis))..
         sum( h , G(n,dis,h) ) =L= nu_e(n,dis)
;


* ---------------------------------------------------------------------------- *
***** Hourly maximum generation caps and constraints related to reserves   *****
* ---------------------------------------------------------------------------- *

con1d_maxprod_dispatchable(n,dis,h)$(map_n_tech(n,dis))..
        G(n,dis,h)
        =L= N_TECH(n,dis)
;

con1e_maxprod_res(n,nondis,h)$(map_n_tech(n,nondis))..
        G_RES(n,nondis,h)
        =L= phi_res(n,nondis,h) * N_TECH(n,nondis)
;

* ---------------------------------------------------------------------------- *
***** Storage constraints *****
* ---------------------------------------------------------------------------- *

con1f_1_stolev_start(n,sto,h)$(map_n_sto(n,sto) AND ord(h) = 1)..
        STO_L(n,sto,h) =E= phi_sto_ini(n,sto) * N_STO_E(n,sto) + STO_IN(n,sto,h)*eta_sto_in(n,sto) - STO_OUT(n,sto,h)/eta_sto_out(n,sto)
;

con1f_2_stolev(n,sto,h)$((ord(h)>1) AND map_n_sto(n,sto))..
         STO_L(n,sto,h) =E= STO_L(n,sto,h-1) + STO_IN(n,sto,h)*eta_sto_in(n,sto) - STO_OUT(n,sto,h)/eta_sto_out(n,sto)
;

con1f_3_ending(n,sto,h)$(ord(h) = card(h) AND map_n_sto(n,sto))..
         STO_L(n,sto,h) =E= phi_sto_ini(n,sto) * N_STO_E(n,sto)
;

con1g_1_stolev_max(n,sto,h)$(map_n_sto(n,sto))..
        STO_L(n,sto,h) =L= N_STO_E(n,sto)
;

con1g_2_maxin_sto(n,sto,h)$(map_n_sto(n,sto))..
        STO_IN(n,sto,h)
        =L= N_STO_P_IN(n,sto)
;

con1g_3_maxout_sto(n,sto,h)$(map_n_sto(n,sto))..
        STO_OUT(n,sto,h)
        =L= N_STO_P_OUT(n,sto)
;

con1h_1_maxout_lev(n,sto,h)$(map_n_sto(n,sto))..
        ( STO_OUT(n,sto,h)
        ) / eta_sto_out(n,sto)
        =L= STO_L(n,sto,h-1)
;

con1h_2_maxin_lev(n,sto,h)$(map_n_sto(n,sto))..
        ( STO_IN(n,sto,h)
        ) * eta_sto_in(n,sto)
        =L= N_STO_E(n,sto) - STO_L(n,sto,h-1)
;

con1i_1_EtoP(n,sto)$(map_n_sto(n,sto))..
        N_STO_E(n,sto) =L= tau_sto(n,sto) * N_STO_P_OUT(n,sto)
;

con1i_2_inout(n,sto)$(map_n_sto(n,sto) AND (ord(sto) = 1 or ord(sto) = 2))..
        N_STO_P_IN(n,sto) =E= N_STO_P_OUT(n,sto)
;

* ---------------------------------------------------------------------------- *
***** Quotas for renewables *****
* ---------------------------------------------------------------------------- *

con1j_minRES(n)..
sum( h , G(n,'bio',h) + sum( map_n_tech(n,nondis) , G_RES(n,nondis,h))
)
        =E= iota * sum( h ,
         sum( map_n_tech(n,dis) , G(n,dis,h)) + sum( map_n_tech(n,nondis) , G_RES(n,nondis,h))
         )
;

* ---------------------------------------------------------------------------- *
***** Extension with electrification *****
* ---------------------------------------------------------------------------- *

conXa_total_demand(n)..
         sum( h , D_X(n,h) ) =E= delta_x(n)
;

conXb_max(n,h)..
        D_X(n,h) =L= nu_x
;



********************************************************************************
***** MODEL *****
********************************************************************************

model DIETER /
obj

con1b_bal

con1c_1_max_I_power
con1c_2_max_I_sto_e
con1c_3_max_I_sto_p_in
con1c_4_max_I_sto_p_out
con1c_5_max_biomass

con1d_maxprod_dispatchable
con1e_maxprod_res

con1f_1_stolev_start
con1f_2_stolev
con1f_3_ending
con1g_1_stolev_max
con1g_2_maxin_sto
con1g_3_maxout_sto
con1h_1_maxout_lev
con1h_2_maxin_lev
con1i_1_EtoP
con1i_2_inout

con1j_minRES

%power_to_x%$ontext
conXa_total_demand
conXb_max
$ontext
$offtext
/;
